<?php

namespace common\service\task_deprecated;

use common\service\StatusService;
use common\service\StepService;
use support\SingletonTrait;

/**
 * 任务废除启用 属性变化处理
 */
class StepAttributeChangeHandler
{
    use SingletonTrait;

    /**
     * 查询任务是否被禁用或者不存在
     * @param $taskList
     * @param $stepCode
     * @return bool
     */
    public function stepCodeTaskDisabled($taskList, $stepCode)
    {
        $closedStatusId = StatusService::getInstance()->getTaskDefaultClosedStatus()['id'];
        $taskStatus = StatusService::getInstance()->getTaskDefaultClosedStatus()['id'];
        foreach ($taskList as $task) {
            if ($task['code'] === $stepCode) {
                $taskStatus = $task['task_status'];
                break;
            }
        }
        return $taskStatus == $closedStatusId;
    }

    /**
     * 禁用属性查询
     * @param $taskList
     * @param int $stepId
     * @return array|string[]
     */
    public function disabledAttrChanged($taskList, int $stepId)
    {
        $step = StepService::getInstance()->getStep($stepId, '*');
        $res = [];
        switch ($step['code']) {
            case 'sketch_design':
                $res = [
                    '_production_method' => '不出图',
                ];
                break;
            case 'hair':
                $res = [
                    '_hair_making' => '无毛发',
                ];
                break;
            case 'comp':
                $res = [
                    '_comp_type' => '无合成',
                ];
                break;
            case 'cloth_solution':
                // 布料解算
                if ($this->stepCodeTaskDisabled($taskList, 'hair_solution')) {
                    $res = [
                        '_cloth_solution' => '不需要解算',
                    ];
                } else {
                    $res = [
                        '_cloth_solution' => '毛发解算',
                    ];
                }
                break;
            case 'hair_solution':
                // 毛发解算
                if ($this->stepCodeTaskDisabled($taskList, 'cloth_solution')) {
                    $res = [
                        '_cloth_solution' => '不需要解算',
                    ];
                } else {
                    $res = [
                        '_cloth_solution' => '布料解算',
                    ];
                }
                break;
            case 'shot_efx':
                if ($this->stepCodeTaskDisabled($taskList, 'other_efx')) {
                    $res = [
                        '_fx' => '无特效',
                    ];
                } else {
                    $res = [
                        '_fx' => '其他特效',
                    ];
                }
                break;
            case 'other_efx':
                if ($this->stepCodeTaskDisabled($taskList, 'shot_efx')) {
                    $res = [
                        '_fx' => '无特效',
                    ];
                } else {
                    $res = [
                        '_fx' => '引擎特效',
                    ];
                }
                break;
            case 'shot_cluster':
                $res = [
                    '_is_cluster' => '非群集镜头',
                ];
                break;
        }
        return $res;
    }

    /**
     * 启用属性变化查询
     * @param $taskList
     * @param int $stepId
     * @return array|string[]
     */
    public function enableAttrChanged($taskList, int $stepId)
    {
        $step = StepService::getInstance()->getStep($stepId, '*');
        $res = [];
        switch ($step['code']) {
            case 'sketch_design':
                $res = [
                    '_production_method' => '概念稿',
                ];
                break;
            case 'hair':
                $res = [
                    '_hair_making' => '有毛发'
                ];
                break;
            case 'comp':
                $res = [
                    '_comp_type' => '有合成'
                ];
                break;
            case 'cloth_solution':
                // 布料解算
                if ($this->stepCodeTaskDisabled($taskList, 'hair_solution')) {
                    $res = [
                        '_cloth_solution' => '布料解算'
                    ];
                } else {
                    $res = [
                        '_cloth_solution' => '布料毛发解算'
                    ];
                }
                break;
            case 'hair_solution':
                // 毛发解算
                if ($this->stepCodeTaskDisabled($taskList, 'cloth_solution')) {
                    $res = [
                        '_cloth_solution' => '毛发解算'
                    ];
                } else {
                    $res = [
                        '_cloth_solution' => '布料毛发解算'
                    ];
                }
                break;
            case 'shot_efx':
                if ($this->stepCodeTaskDisabled($taskList, 'other_efx')) {
                    $res = [
                        '_fx' => '引擎特效'
                    ];
                } else {
                    $res = [
                        '_fx' => '混合特效'
                    ];
                }
                break;
            case 'other_efx':
                if ($this->stepCodeTaskDisabled($taskList, 'shot_efx')) {
                    $res = [
                        '_fx' => '其他特效'
                    ];
                } else {
                    $res = [
                        '_fx' => '混合特效'
                    ];
                }
                break;
            case 'shot_cluster':
                $res = [
                    '_is_cluster' => '群集镜头',
                ];
                break;
        }
        return $res;
    }
}
